﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
using Microsoft.Xna.Framework.Content;

namespace MyCraft.Minecraft_2D.Blocs
{
    class Plank : Bloc
    {
        #region Attributs
        bool _isHorizontal;
        Texture2D _image0, _image90;
        #endregion

        #region Constructeur
        public Plank(Vector2 position, double timer, ContentManager content)
            : base(timer, 20)
        {
            _light = -6;
            _minLight = 0;
            _id = 4;
            _name = "Plank";
            _percent = 0;
            _color = Color.Peru;
            _image0=(content != null) ? content.Load<Texture2D>(@"Blocs\Plank") : null;
            _image90 = (content != null) ? content.Load<Texture2D>(@"Blocs\Plank - 90") : null;

            SwitchOrientation(position);

            _actionBloc = delegate(Block b, Vector2 p, double t)
            {
                SwitchOrientation(p);
                return this;
            };
        }
        #endregion

        #region Proprietes
        #endregion

        #region Methodes
        private void SwitchOrientation(Vector2 position)
        {
            if (position.Y <= 0.25f || position.Y >= 0.75f)
                _isHorizontal = false;
            else
                _isHorizontal = true;

            if (_isHorizontal)
                _image = _image0;
            else
                _image = _image90;
        }

        public override TypeBloc OnNew(Block bloc)
        {
            return TypeBloc.Plank;
        }
        #endregion
    }
}
